package cz.muni.fi.pv112.cranesimulator.scene.items;

/**
 * Class representing camera in the scene
 *
 * @author Michal Ďuriš
 */
public class Camera implements CameraInterface {

    private CameraMode cameraMode = CameraMode.FREE_CAMERA_MODE;

    private float moveStep = 1.0f;
    private float rotateAngleStep = 2.0f;

    /**
     * Position of the camera in the scene
     * Store x, y, z coordinations of a camera
     */
    private float[] position = {0.0f, 210.0f, -110.0f};
//  CABIN CAMERA    private float[] position = {-4.0f, 190.0f, 0.0f};
// rider   private float[] position = {-35.0f, 190.0f, 0.0f};

    /**
     * Orientation of a camera in Scene.
     * Store x, y, z angles of a camera
     */
    private float[] orientation = {0.0f, 0.0f, 0.0f};
// rider   private float[] orientation = {-90.0f, 90.0f, 0.0f};
// CAbin   private float[] orientation = {0.0f, 90.0f, 0.0f};

    public Camera() {
    }

    public Camera(CameraMode cameraMode) {
        init(cameraMode);
    }

    private void init(CameraMode cameraMode) {
        switch (cameraMode) {
            case FREE_CAMERA_MODE:
                setPosition(0.0f, 210.0f, -110.0f);
                setOrientation(0.0f, 0.0f, 0.0f);
                this.cameraMode = cameraMode;
                break;

            case CABIN_CAMERA_MODE:
                setPosition(-4.0f, 190.0f, 0.0f);
                setOrientation(0.0f, 90.0f, 0.0f);
                this.cameraMode = cameraMode;
                break;

            case LIFTING_ROD_CAMERA_MODE:
                setPosition(-35.0f, 190.0f, 0.0f);
                setOrientation(-90.0f, 90.0f, 0.0f);
                this.cameraMode = cameraMode;
                break;
            default:
                setPosition(new float[3]);
                setOrientation(new float[3]);
                this.cameraMode = CameraMode.FREE_CAMERA_MODE;
        }
    }

    @Override
    public float[] getPosition() {
        return position;
    }

    @Override
    public void setPosition(float[] position) {
        this.position = position;
    }

    @Override
    public void setPosition(float x, float y, float z) {
        position[X_AXIS] = x;
        position[Y_AXIS] = y;
        position[Z_AXIS] = z;
    }

    @Override
    public float[] getOrientation() {
        return orientation;
    }

    @Override
    public void setOrientation(float[] orientation) {
        this.orientation = orientation;
    }

    @Override
    public void setOrientation(float x, float y, float z) {
        orientation[X_AXIS] = x;
        orientation[Y_AXIS] = y;
        orientation[Z_AXIS] = z;
    }

    @Override
    public float getPositionX() {
        return position[X_AXIS];
    }

    @Override
    public float getPositionY() {
        return position[Y_AXIS];
    }

    @Override
    public float getPositionZ() {
        return position[Z_AXIS];
    }

    @Override
    public float getOrientationAngleX() {
        return orientation[X_AXIS];
    }

    @Override
    public float getOrientationAngleY() {
        return orientation[Y_AXIS];
    }

    @Override
    public float getOrientationAngleZ() {
        return orientation[Z_AXIS];
    }

    @Override
    public float getMoveStep() {
        return moveStep;
    }

    @Override
    public void setMoveStep(float moveStep) {
        this.moveStep = moveStep;
    }

    @Override
    public float getRotateAngleStep() {
        return rotateAngleStep;
    }

    @Override
    public void setRotateAngleStep(float rotateAngleStep) {
        this.rotateAngleStep = rotateAngleStep;
    }

    public CameraMode getCameraMode() {
        return cameraMode;
    }

    public void setCameraMode(CameraMode cameraMode) {
        init(cameraMode);
    }

    @Override
    public boolean isMoveEnabled() {

        return cameraMode != CameraMode.CABIN_CAMERA_MODE && cameraMode
                != CameraMode.LIFTING_ROD_CAMERA_MODE;
    }

    @Override
    public boolean isRotationEnabled() {

        return cameraMode != CameraMode.LIFTING_ROD_CAMERA_MODE;
    }

}
